package com.elitel.common.utils;

import java.io.File;

import javax.annotation.PostConstruct;

import org.apache.commons.io.FileUtils;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

@Component
public class ScriptSqlFieldTypeHelper{

    private String scriptSqlFieldTypePath = "classpath:scriptSqlFieldType.json";
    private JSONObject scriptSqlFieldType;

    @PostConstruct
    private void init(){

        JSONParser parser = new JSONParser();
        try{
            File jsonFile = ResourceUtils.getFile(scriptSqlFieldTypePath);
            scriptSqlFieldType = (JSONObject) parser.parse(FileUtils.readFileToString(jsonFile, "UTF-8"));
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public String getSqlFieldTypeFromJsonFile(String fieldName){
        return (String)scriptSqlFieldType.get(fieldName);
    }



}
